<template>
  <view class="cardbox" v-if="hosedata"> 
        <view class="l">
			<image :src="ip+'/'+hosedata.img" mode="aspectFill"></image>
		</view>
        <view class="r">
			<view class="tit">{{type}} | {{hosedata.context}}</view>
			<view class="con">{{hosedata.sum}}室·{{hosedata.erea}}m^2·{{hosedata.title}}</view>
			<view class="pri">{{hosedata.price * 30}} <text class="yue">元/月</text> </view>
			<view class="time"> <view class="">{{data.updatedAt}}</view> <view v-if="his" class="iconfont icon-shanchu" @click.stop="dele"></view> <view v-else class="iconfont icon-shanchu" @click.stop="share"></view> </view>
		</view>
  </view>
</template>

<script setup>
	import {ref,onMounted,computed} from 'vue'
		import userstore from "@/store/userlogin.js"
	import {getfindid,gethoseleavelove,gethosealllove,getdelehistroy} from '@/api/index.js'
	import { ip } from '../../utils/getinfo';
	const emit=defineEmits(['delelovehise','delehis'])
		const useuserstore=userstore()
	 const prop=defineProps(['data',"his"])
	 const hosedata=ref()
	 const alllove=async ()=>{
	 	 const rudata= await gethosealllove()
	 	  useuserstore.userlove=rudata.data
	 }
	 const leavelove=async ()=>{
	 	const rudata=await gethoseleavelove(prop.data.hoseid,useuserstore.userlogin.id)
		emit('delelovehise',prop.data.id)
	 	alllove()
	 }
	 onMounted(()=>{
		 gethosedata()
	 })
	 const dele=async()=>{
		 uni.showModal({
		 	title:"提示",
		 	content:"确定要删除吗？",
		 	success(e) {
		 		if(e.confirm){
		 			  const send=async()=>{
						  await getdelehistroy(prop.data.id)
						  emit('delehis',prop.data.id)
					  }
					  send()
		 		}
		 	}
		 })
		  
	 }
	 const gethosedata=async()=>{
		 
		 const rudata=await getfindid(prop.data.hoseid)
		 hosedata.value=rudata.data
	 }
	 const type=computed(()=>{
	 	if(hosedata.value){
	 		if(hosedata.value.type=='0') return "整租"
	 		if(hosedata.value.type=='1') return "合租/单间"
	 		if(hosedata.value.type=='2') return "公寓"
	 		if(hosedata.value.type=='3') return "短租"
	 	}
	 		 
	     })
		 const share=()=>{
			uni.showModal({
				title:"提示",
				content:"确定要删除吗？",
				success(e) {
					if(e.confirm){
						   leavelove()
					}
				}
			})
		 }
</script>

<style lang="scss" scoped>
	.cardbox{
		height: 100%;
		width: 100%;
		display: flex;
		padding: 20rpx;
		.l{
			height: 100%;
			width: 40%;
			image{
				height: 100%;
				width: 100%;
				border-radius: 10rpx;
			}
		}
		.r{
			flex: 1;
			display: flex;
			flex-direction: column;
			overflow: hidden;
			padding-left: 10rpx;
			>view{
				flex: 1;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
				display: flex;
				align-items: center;
			}
			.tit{
				flex: none;
				display: block;
				font-size: 31rpx;
				font-weight: 700;
				height: fit-content;
			}
			.con{
				font-size: 25rpx;
			}
			.pri{
				font-size: 32rpx;
				color: #ff9900;
				font-weight: 700;
				.yue{
					font-size: 23rpx;
					margin-bottom: -5rpx;
				}
			}
			.time{
				font-size: 21rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;	
			}
		}
	}
</style>